package com.example.survey_determination.controller;


import com.example.survey_determination.service.ReportedInfoService;
import com.example.survey_determination.service.SurveyLossInfoService;

import com.example.survey_determination.service.TaskInfoService;
import entity.SurveyLossInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import java.util.List;


/**
 * (SurveyLossInfo)表控制层
 *
 * @author makejava
 * @since 2022-01-04 16:44:18
 */
@CrossOrigin(methods = {RequestMethod.GET,RequestMethod.POST})
@RestController
@RequestMapping("survey_loss_info")
public class SurveyLossInfoController {
    /**
     * 服务对象
     */
    @Resource
    private SurveyLossInfoService surveyLossInfoService;
    @Resource
    private ReportedInfoService reportedInfoService;
    @Resource
    private TaskInfoService taskInfoService;

    @RequestMapping("selectRecognizee")
    public String selectRecognizee(String claimmainid) {
        return this.surveyLossInfoService.selectRecognizee(claimmainid);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<SurveyLossInfo> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.surveyLossInfoService.queryById(id));
    }
    @RequestMapping("insertSurveyLossInfo")
    public int insertSurveyLossInfo(SurveyLossInfo surveyLossInfo) {
        return this.surveyLossInfoService.insertSurveyLossInfo(surveyLossInfo);
    }
    @RequestMapping("selectAll")
    public List<SurveyLossInfo> selectAll(Integer dispose_people_number) {
        return this.surveyLossInfoService.selectAll(dispose_people_number);
    }
    /**
     * 新增数据
     *
     * @param surveyLossInfo 实体
     * @return 新增结果
     */
    @RequestMapping("add")
    public SurveyLossInfo add(SurveyLossInfo surveyLossInfo) {
        System.out.println(surveyLossInfo.toString());
        return this.surveyLossInfoService.insert(surveyLossInfo);
    }

    /**
     * 编辑数据
     *
     * @param surveyLossInfo 实体
     * @return 编辑结果
     */
    @RequestMapping("edit")
    public ResponseEntity<SurveyLossInfo> edit(SurveyLossInfo surveyLossInfo) {
        return ResponseEntity.ok(this.surveyLossInfoService.update(surveyLossInfo));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.surveyLossInfoService.deleteById(id));
    }
    @RequestMapping("updateSurveyLossInfo_surveyStatus")
    public int updateSurveyLossInfo_surveyStatus(String survey_status,String claimmainid) {
        if(survey_status=="注销"||survey_status.equals("注销")){
            this.reportedInfoService.updateReported_info_case_state(survey_status,claimmainid);
            this.taskInfoService.updateService_schedule(claimmainid);
        }
        return this.surveyLossInfoService.updateSurveyLossInfo_surveyStatus(survey_status,claimmainid);
    }

}

